<template>
	<view class="page-box">
		<uni-section title="销售信息" type="line"></uni-section>
		<view class="form-box">		
			<view class="two-line-box">
				<view>分佣比例</view>
				<view class="two-line">
					<view>
						<input v-model="saler_ratio" type="text" placeholder="请填写买方佣金" placeholder-style="color:#bdbdbd" />
						<text>%</text>
					</view>
					<view>
						<input v-model="buyer_ratio" type="text" placeholder="请填写卖方佣金" placeholder-style="color:#bdbdbd" />
						<text>%</text>
					</view>
				</view>
			</view>
			<view>
				<view>售卖状态</view>
				<block>
					<picker @change="bindPickerChange($event)" :range="saleStatus.array" range-key="val">
						<view :class="saleStatus.index === '' ? 'c-gray' : ''">{{ saleStatus.index === "" ? '请选择'+ saleStatus.lable : saleStatus.array[saleStatus.index].val}}</view>
					</picker>
					<uni-icons type="arrowdown" :color="'#bdbdbd'" size="16" />
				</block>
			</view>					
			<view>
				<view>售卖楼栋</view>
				<input v-model="sale_building" type="text" placeholder="请填写售卖楼栋号" placeholder-style="color:#bdbdbd" />
				<text>栋</text>
			</view>
			<view>
				<view>最新开盘</view>
				<input v-model="last_open" type="text" placeholder="选择日期" placeholder-style="color:#bdbdbd" />
			</view>
			<view>
				<view>售楼地址</view>
				<input v-model="sale_building_address" type="text" placeholder="请填写售楼地址" placeholder-style="color:#bdbdbd" />
			</view>
			<view>
				<view>预售证</view>
				<input v-model="pre_sale_permit" type="text" placeholder="请填写预售证编号" placeholder-style="color:#bdbdbd" />
			</view>
			<view>
				<view>发证时间</view>
				<input v-model="issue_time" type="text" placeholder="请填写发证时间" placeholder-style="color:#bdbdbd" />
			</view>
			<view>
				<view>绑定楼栋</view>
				<input v-model="bind_building" type="text" placeholder="请填写绑定楼栋" placeholder-style="color:#bdbdbd" />
			</view>
		</view>
		<view class="big-btn" @click="fnSubmit">发布房源</view>
	</view>
</template>

<script>
import uniSection from '@/components/uni-section/uni-section.vue';
import store from '@/store/store.vue'
export default {
	components: {
		uniSection
	},
	onLoad(option) {		
		this.house = JSON.parse(decodeURIComponent(option.param))		
		this.house.sale_status = 0
	},
	data() {
		return {
			saler_ratio: '',				
			buyer_ratio: '',
			sale_status:'',
			sale_building :'',
			last_open :'',
			sale_building_address :'',
			pre_sale_permit : '',
			issue_time : '',
			bind_building :'',
			saleStatus:{
				lable: '售卖状态',
				name: 'sale_status',
				index: '',
				array: [{ val: '在售' }, { val: '未开盘' }]
			},
		}
	},
	methods: {
		bindPickerChange: function(e) {
			console.log(e.detail.value)
			this.saleStatus.index = e.detail.value
			this.house.sale_status = parseInt(e.detail.value) + 1	
		},
		fnSubmit() {
			this.house.commission_share_ratio = this.saler_ratio + ';' + this.buyer_ratio			
			this.house.sale_building = this.sale_building
			this.house.last_open = this.last_open
			this.house.sale_building_address = this.sale_building_address
			this.house.pre_sale_permit = this.pre_sale_permit
			this.house.issue_time = this.issue_time
			this.house.bind_building = this.bind_building		
			let _this = this		
			let arr = [
				'saler_ratio', 'buyer_ratio','sale_status', 'sale_building','last_open',
				'sale_building_address', 'pre_sale_permit', 'issue_time', 'bind_building'				
			]
			let flag = false
			for(let k in arr){
				if(this[k] === ''){
					flag = true
					break
				}
			}	
			if(flag){
				uni.showModal({
					content: '请填写完整'
				});	
				return
			}
			
			uni.request({
			    url: store.url + '/house/release_new_house',
				method: 'POST',
			    data: JSON.stringify(_this.house),
			    header: {
					"content-type": "application/json;charset=utf-8"						
			    },
			    success: (res) => {		
					console.log(res)
					if(res.data.status == 'success'){
						//1新房 2二手房 3租房
						let _url = '/pages/house/state?param=' + encodeURIComponent(JSON.stringify(3))
						if(getApp().globalData.inviter_id == 0){
							_url = '/pages/house/state?param=' + encodeURIComponent(JSON.stringify(1))
						}
						uni.navigateTo({
							url: _url
						})	
						uni.navigateTo({
							url: _url
						})							
					}else{
						uni.showModal({
						    title: '提示',
						    content: '提交失败: ' + res.data.message
						});									
					}										        
			    },
				fail: (res)=>{
					uni.showModal({
					    title: '提示',
					    content: '访问服务器失败: ' + res.data.message
					});						
				}
			});				
		}
	}
};
</script>

<style lang="scss" scoped>
.page-box {
	padding-bottom: 88rpx;
	box-sizing: border-box;

	/deep/ .uni-section {
		margin-top: 0;
		background: #fff;
	}

	/deep/ .line {
		background-color: #f13b32;
	}
}

.form-box {
	margin-bottom: 20rpx;
	padding-left: 40rpx;
	box-sizing: border-box;
	background: #fff;

	> view {
		display: flex;
		border-bottom: 1px solid #e5e5e5;
		box-sizing: border-box;
		align-items: center;
		font-size: 24rpx;

		&:last-of-type {
			border-bottom: none;
		}
		
		&.two-line-box {
			align-items: flex-start;
		}

		> view {
			width: 140rpx;
			line-height: 80rpx;
			font-size: 24rpx;

			&.two-line {
				flex: 1;
				
				view {
					display: flex;
					align-items: center;
					border-bottom: 1px solid #e5e5e5;
					
					&:last-of-type {
						border-bottom: none;
					}
					
					input {
						flex: 1;
					}
				}

			}
		}

		input,
		.uni-input {
			padding: 20rpx 40rpx 20rpx 0;
			box-sizing: border-box;
			flex: 1;
			height: 80rpx;
			line-height: 40rpx;
		}

		text,
		uni-icons {
			padding: 0 20rpx;
			box-sizing: border-box;
		}

		picker {
			flex: 1;
			
			view {
				font-size: 24rpx;
			}
		}
	}
}

.big-btn {
	position: fixed;
	left: 0;
	bottom: 0;
	width: 100%;
	line-height: 88rpx;
	text-align: center;
	color: #fff;
	background: #f13b32;
}
</style>

	
